<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\utils\Constant;
use app\index\logic\BacteriaLogic;
use app\index\logic\UserLogic;

/**
 * Created by PhpStorm.
 * User: Orange
 * Date: 2018/5/5
 * Time: 16:01
 */
class User extends Frontend
{


    /**
     * 根据token获取用户信息
     * @return \think\response\Json
     */
    public function ajax_get_user_info_token()
    {
        $token = $this->request->param('token');
        $logic = new UserLogic();
        $result = $logic->getUserByToken($token);
        if ($result['status'] == 1) {
            return $this->returnJson('', Constant::CODE_SUCCESS, $result['data']);
        } else {
            return $this->returnJson('获取失败!', Constant::CODE_ERROR);
        }
    }


    /**
     * ajax根据微信code获取用户信息
     * @return \think\response\Json
     */
    public function ajax_get_user_info()
    {
        $code = $this->request->param('code');
        $logic = new UserLogic();
        $result = $logic->getUserByCode($code);
        if ($result['status'] == 1) {
            return $this->returnJson('', Constant::CODE_SUCCESS, $result['data']);
        } else {
            return $this->returnJson('获取失败!', Constant::CODE_ERROR, $result['error']);
        }
    }

    /**
     * ajax登录
     * @return \think\response\Json
     */
    public function ajax_login()
    {
        $phone = $this->request->param('phone');
        $password = $this->request->param('password');
        $ip = $this->request->ip();
        $logic = new UserLogic();
        $result = $logic->Login($phone, $password, $ip);
        if ($result['status'] == 1) {
            return $this->returnJson('', Constant::CODE_SUCCESS, $result['data']);
        } else {
            return $this->returnJson('获取失败!', Constant::CODE_ERROR, $result['error']);
        }
    }
    /**
     * 会员审核数量
     * @return \think\response\Json
     */
    public function ajax_get_member_verify_num()
    {
        $result = $this->check();
        if (!$result['success']) {
            return $this->returnJson($result['msg'], $result['code']);
        }
        $token = $this->request->param('token');
        $logic = new UserLogic();
        $result = $logic->getMemeberVerifyNum($token);
        if ($result['status'] == 1) {
            return $this->returnJson('', Constant::CODE_SUCCESS, $result['data']);
        } else {
            return $this->returnJson('获取失败!', Constant::CODE_ERROR, $result['error']);
        }
    }
    /**
     * 会员搜索历史
     * @return \think\response\Json
     */
    public function ajax_get_member_access_log()
    {
        $result = $this->check();
        if (!$result['success']) {
            return $this->returnJson($result['msg'], $result['code']);
        }
        $token = $this->request->param('token');
        $logic = new UserLogic();
        $result = $logic->getMemeberAccessLog($token);
        if ($result['status'] == 1) {
            return $this->returnJson('', Constant::CODE_SUCCESS, $result['data']);
        } else {
            return $this->returnJson('获取失败!', Constant::CODE_ERROR, $result['error']);
        }
    }
//    public function test()
//    {
//        $logic = new BacteriaLogic();
//        $logic->sendMessage();
//    }
}